package com.itheima.controller;

import com.itheima.R;
import com.itheima.pojo.SmsHomeRecommendSubject;
import com.itheima.service.SmsHomeAdvertiseService;
import com.itheima.service.SmsHomeRecommendSubjectService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Hakuna Matata
 * @date 2022-10-13-15:45
 */
@RestController
@RequestMapping("home/recommendSubject")
public class SmsHomeRecommendSubjectController {

    @Autowired
    private SmsHomeRecommendSubjectService recommendSubjectService;

    /**
     * 添加首页推荐专题
     *
     * @param recommendSubject
     * @return
     */
    @PostMapping("/create")
    public R recommendSubjectCreate(@RequestBody SmsHomeRecommendSubject recommendSubject) {
        recommendSubjectService.create(recommendSubject);
        return R.success("添加专题推荐成功!");
    }

    /**
     * 批量删除推荐
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R recommendSubjectDelete(Integer[] ids) {
        recommendSubjectService.delete(ids);
        return R.success("删除专题推荐成功!");
    }

    /*
     * 分页查询推荐
     */
    @GetMapping("/list")
    public R recommendSubjectList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                  String subjectName,
                                  Integer recommendStatus) {
        PageResult pageResult = recommendSubjectService.list(pageNum, pageSize, subjectName, recommendStatus);
        return R.success(pageResult);
    }

    /**
     * 批量修改推荐状态
     *
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R updateRecommendStatus(Integer[] ids, Integer recommendStatus) {
        recommendSubjectService.updateStatus(ids, recommendStatus);
        return R.success("修改状态成功!");
    }

    /**
     * 修改推荐排序
     *
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public R updateSortId(@PathVariable("id") Long id, Integer sort) {
        recommendSubjectService.updateSortId(id, sort);
        return R.success("修改排序成功!");
    }
}
